package lcr;

public class Test0042 {
}

class RecentCounter {
    private static final int N = 3002;

    private final int[] queue = new int[N];
    private int head;
    private int tail;

    public int ping(int t) {
        int first = t - 3000;
        while (head != tail && queue[head] < first) {
            head = (head + 1) % N;
        }
        queue[tail] = t;
        tail = (tail + 1) % N;
        return (tail - head + N) % N;
    }
}